// WndListEvent.cpp : implementation file
//

#include "stdafx.h"
#include "BBSimple.h"
#include "WndListEvent.h"

#include "StatusMgr.h"
#include "../_inc/def_base.h"

// CWndListEvent
IMPLEMENT_DYNAMIC(CWndListEvent, CWnd)

CWndListEvent::CWndListEvent()
{
	m_bInitList = FALSE;

	m_bChecked = FALSE;
	m_pListMgr = NULL;

	int i;
	for (i=0;i<MAX_REC_TYPE;i++)
		m_bRecType[i] = (i != REC_NORMAL);

}

CWndListEvent::~CWndListEvent()
{
}


BEGIN_MESSAGE_MAP(CWndListEvent, CWnd)
	ON_WM_SIZE()
	ON_WM_CREATE()
	ON_WM_SHOWWINDOW()
	ON_NOTIFY(HDN_ENDTRACK, 0, OnEndtrackSkinList)
	ON_WM_PAINT()
	ON_WM_ERASEBKGND()
	ON_MESSAGE(WM_PLB_MESSAGE, OnPlbMessage)
	ON_MESSAGE(WM_CTL_MESSAGE, OnCtlMessage)
END_MESSAGE_MAP()



// CWndListEvent message handlers

int CWndListEvent::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
	if (CWnd::OnCreate(lpCreateStruct) == -1)
		return -1;

// 	LPST_WND_POS lpWndPos = theApp.WndPos.GetAt(wpListEvent);
// 	m_nMode = lpWndPos->nMode;

	if (!m_SkinList.Create(WS_CHILD|WS_VISIBLE|LVS_REPORT , CRect(0, 0, 0, 0), this, IDC_LIST_EVENT))
		return -1;	

// 	lpWndPos = theApp.WndPos.GetAt(wpListEvent);
// 
// 	m_nFontHeight = 14;
// 
// 	LOGFONT lf;
// 	memset(&lf, 0, sizeof(LOGFONT));
// 	lf.lfHeight = m_nFontHeight;
// 	lf.lfWeight = FW_NORMAL;
// 	_tcscpy_s(lf.lfFaceName, sizeof(lf.lfFaceName)/sizeof(lf.lfFaceName[0]), DEFAULT_FONT);
// 	m_ListFont.CreateFontIndirect(&lf);
// 
// 	m_SkinList.SetFont(&m_ListFont, TRUE);
// 	m_SkinList.Init(TRUE, m_nFontHeight);
// 	m_SkinList.SetBkColor(lpWndPos->dwColorBackground);
// 	m_SkinList.SetTextColor(lpWndPos->dwColorText);
// 	m_SkinList.SetItemIndicateColor(lpWndPos->dwColorLevel[0]);
// 	m_SkinList.SetItemColor(lpWndPos->dwColorLevel[1], lpWndPos->dwColorLevel[2]);

	return 0;
}

void CWndListEvent::InitListCtrl()
{
	int nWidth1, nWidth2, nWidth3;	
	int nWidth;
	int i, val;

	nWidth1 = (m_nListWidth-20)*10/37;
	nWidth2 = (m_nListWidth-20)*10/21;
	nWidth3 = (m_nListWidth-20)*10/42;

	nWidth = m_nListWidth - (nWidth1+nWidth2+nWidth3+20);
	for (i=0;i<nWidth;i++)
	{
		val = i%3;
		if(val==0)
			nWidth1++;
		else if (val==1)
			nWidth2++;
		else
			nWidth3++;
	}

	if (m_bInitList)
	{
		CTimeList *ptIndex;
		TCHAR tzStr[64];
		m_SkinList.SetColumnWidth(0, 20);
		m_SkinList.SetColumnWidth(1, nWidth1);
		m_SkinList.SetColumnWidth(2, nWidth2);
		m_SkinList.SetColumnWidth(3, nWidth3);	

		for (i=0;i<m_arrPlayList.GetSize();i++)
		{
			// End Time
			ptIndex = m_arrPlayList.GetAt(i);
			m_UtilTime.GetTimeString(ptIndex->GetEndTime(), tzStr);
			m_SkinList.SetItemText(i, 3, tzStr);
		}
	}
	else
	{
		m_SkinList.InsertColumn(0, _T(""), LVCFMT_CENTER, 20);
		m_SkinList.InsertColumn(1, m_pListMgr->GetString(5), LVCFMT_CENTER, nWidth1);
		m_SkinList.InsertColumn(2, m_pListMgr->GetString(2), LVCFMT_CENTER, nWidth2);
		m_SkinList.InsertColumn(3, m_pListMgr->GetString(3), LVCFMT_CENTER, nWidth3);	
		m_SkinList.DeleteAllItems();
	}

	m_bInitList = TRUE;

}

void CWndListEvent::OnPaint()
{
	CPaintDC dc(this);
// 	CRect rect;
// 	CBitmap bmp, *pOldBmp;
// 	CDC dcMemory;
// 
// 	CBitmap *pBmpBg, *pOldBmpBg;
// 	CDC dcBg;
// 	LPST_BMP_INFO lpBmpInfo = theApp.BmpInfo.GetAt(biListBG);
// 	LPST_WND_POS lpWndPos = theApp.WndPos.GetAt(wpListEvent);
// 	CRect rtDiv = lpWndPos->rtDiv;
// 	CRect rtImg = lpBmpInfo->rtImageRect;
// 
// 	if (lpBmpInfo->hbmpImage == NULL)
// 		return;
// 
// 	this->GetClientRect(&rect);
// 
// 	bmp.CreateCompatibleBitmap(&dc, rect.Width(), rect.Height());
// 	dcMemory.CreateCompatibleDC(&dc);
// 
// 	pOldBmp = dcMemory.SelectObject(&bmp);
// 
// 	dcBg.CreateCompatibleDC(&dc);
// 	pBmpBg = CBitmap::FromHandle(lpBmpInfo->hbmpImage);
// 	pOldBmpBg = dcBg.SelectObject(pBmpBg);
// 
// 	dcMemory.BitBlt(0, 0, rtDiv.left, rtDiv.top, &dcBg, 0, 0, SRCCOPY);
// 	dcMemory.StretchBlt(rtDiv.left, 0, rect.Width()-(rtDiv.left+rtDiv.right), rtDiv.top,
// 		&dcBg, rtDiv.left, 0, rtImg.Width()-(rtDiv.left+rtDiv.right), rtDiv.top, SRCCOPY);
// 	dcMemory.BitBlt(rect.Width()-rtDiv.right, 0, rtDiv.right, rtDiv.top,
// 		&dcBg, rtImg.Width()-rtDiv.right, 0, SRCCOPY);
// 	dcMemory.StretchBlt(0, rtDiv.top, rtDiv.left, rect.Height()-(rtDiv.top+rtDiv.bottom),
// 		&dcBg, 0, rtDiv.top, rtDiv.left, rtImg.Height()-(rtDiv.top+rtDiv.bottom), SRCCOPY);
// 	dcMemory.StretchBlt(rtDiv.left, rtDiv.top,
// 		rect.Width()-(rtDiv.left+rtDiv.right), rect.Height()-(rtDiv.top+rtDiv.bottom),
// 		&dcBg, rtDiv.left, rtDiv.top,
// 		rtImg.Width()-(rtDiv.left+rtDiv.right), rtImg.Height()-(rtDiv.top+rtDiv.bottom),
// 		SRCCOPY);
// 	dcMemory.StretchBlt(rect.Width()-rtDiv.right, rtDiv.top, rtDiv.right, rect.Height()-(rtDiv.top+rtDiv.bottom),
// 		&dcBg, rtImg.Width()-rtDiv.right, rtDiv.top,
// 		rtDiv.right, rtImg.Height()-(rtDiv.top+rtDiv.bottom),
// 		SRCCOPY);
// 	dcMemory.BitBlt(0, rect.Height()-rtDiv.bottom, rtDiv.left, rtDiv.bottom,
// 		&dcBg, 0, rtImg.Height()-rtDiv.bottom, SRCCOPY);
// 	dcMemory.StretchBlt(rtDiv.left, rect.Height()-rtDiv.bottom,
// 		rect.Width()-(rtDiv.left+rtDiv.right), rtDiv.bottom,
// 		&dcBg, rtDiv.left, rtImg.Height()-rtDiv.bottom,
// 		rtImg.Width()-(rtDiv.left+rtDiv.right), rtDiv.bottom,
// 		SRCCOPY);
// 	dcMemory.BitBlt(rect.Width()-rtDiv.right, rect.Height()-rtDiv.bottom, rtDiv.left, rtDiv.bottom,
// 		&dcBg, rtImg.Width()-rtDiv.right, rtImg.Height()-rtDiv.bottom, SRCCOPY);
// 
// 	dc.BitBlt(0, 0, rect.Width(), rect.Height(), &dcMemory, 0, 0, SRCCOPY);
// 
// 	dcBg.SelectObject(pOldBmpBg);
// 	dcBg.DeleteDC();
// 
// 	dcMemory.SelectObject(pOldBmp);
// 	dcMemory.DeleteDC();

}

void CWndListEvent::OnSize(UINT nType, int cx, int cy)
{
	CWnd::OnSize(nType, cx, cy);

	if ((cx==0)||(cy==0))
		return;

// 	LPST_WND_POS lpWndPos;
// 	LPST_BMP_INFO lpBmpInfo = theApp.BmpInfo.GetAt(biScrl_v_span);
// 	CRect rtStickTo;

	int nScrollWidth = 12;//lpBmpInfo->rtImageRect.Width();

	if (m_SkinList)
	{
// 		lpWndPos = theApp.WndPos.GetAt(wpListEvent_file);
// 		rtStickTo = lpWndPos->rtStickTo;
// 		rtStickTo.right += nScrollWidth;
// 		m_nListWidth = cx-(rtStickTo.left+rtStickTo.right);
// 		theApp.SetWindowPosition(&m_SkinList, cx, cy, lpWndPos->rtWndPos, rtStickTo);
		//m_SkinList.PositionScrollBars();

		m_SkinList.MoveWindow(0, 0, 307, 268);
		InitListCtrl();
	}
}

void CWndListEvent::OnShowWindow(BOOL bShow, UINT nStatus)
{
	CWnd::OnShowWindow(bShow, nStatus);


}

void CWndListEvent::OnEndtrackSkinList(NMHDR* pNMHDR, LRESULT* pResult) 
{
	HD_NOTIFY *phdn = (HD_NOTIFY *) pNMHDR;

	//m_SkinList.UpdateHScrollPos();

	*pResult = 0;
}

int CWndListEvent::GetListItem(int nStartCount)
{
	if (nStartCount>=m_SkinList.GetItemCount())
	{
		return -1;
	}
// 	else if (nStartCount == -1)
// 		nStartCount = m_SkinList.GetItemIndicate();
// 	else if (nStartCount < -1)
// 		return -1;
// 	m_SkinList.SetItemIndicate(nStartCount);
	return nStartCount;
}

int CWndListEvent::GetSelectedItem()
{
	return 2;//m_SkinList.GetItemIndicate();
}

void CWndListEvent::MergetList()
{
	int i;
	int nLoop;
	int nArr = MAX_REC_TYPE-1;
	CSortedArray <CTimeList *, CTimeList *> *pArrIndex[MAX_REC_TYPE];
	CSortedArray <CTimeList *, CTimeList *> arrRecList[MAX_REC_TYPE];
	CSortedArray <CTimeList *, CTimeList *> arrCompareTemp;
	CSortedArray <CTimeList *, CTimeList *> *pRecList;

	int m1, m2;
	BOOL bBreak;
	int nCompare;
	CTimeList *ptIndex1, *ptIndex2;
	CTimeList *ptPlayList;

	nLoop = 0;
	for (i=1;i<MAX_REC_TYPE;i++)
	{
		pRecList = m_pListMgr->GetRecList(i);
		if (m_bRecType[i] && (pRecList->GetSize()>0))
		{
			for (m1=0;m1<pRecList->GetSize();m1++)
			{
				ptIndex1 = new CTimeList();
				ptIndex2 = pRecList->GetAt(m1);
				*ptIndex1 = *ptIndex2;
				arrRecList[i].Add(ptIndex1);
			}

			pArrIndex[nLoop] = &arrRecList[i];
			nLoop++;
		}
	}

	if (nLoop==0)
		return;

	for (i=0;i<m_arrPlayList.GetSize();i++)
	{
		ptPlayList = m_arrPlayList.GetAt(i);
		delete ptPlayList;
	}
	m_arrPlayList.RemoveAll();
	if (nLoop==1)
	{
		for (i=0;i<pArrIndex[0]->GetSize();i++)
			m_arrPlayList.Add(pArrIndex[0]->GetAt(i));
	}
	else
	{
		while (TRUE)
		{
			//////////////////////////////////////////////////////////////////////////
			//merge nLoop-1 and nLoop-2 to m_arrPlayList
			m1 = 0;
			for (m2=0;m2<pArrIndex[nLoop-1]->GetSize();m2++)
			{
				ptIndex1 = pArrIndex[nLoop-1]->GetAt(m2);

				bBreak = FALSE;
				while (!bBreak)
				{
					if (m1>=pArrIndex[nLoop-2]->GetSize())
						break;

					ptIndex2 = pArrIndex[nLoop-2]->GetAt(m1);

					nCompare = ptIndex2->CompareTime(*ptIndex1);

					switch (nCompare)
					{
					case -6:
						ptPlayList = new CTimeList();
						*ptPlayList = *ptIndex2;
						ptPlayList->SetEndTime(ptIndex1->GetStartTime(), ptIndex1->GetStartMilliSec());
						m_arrPlayList.Add(ptPlayList);

						ptIndex2->SetStartTime(ptIndex1->GetEndTime(), ptIndex1->GetEndMilliSec());
						bBreak = TRUE;
						break;
					case -5:
					case -4:
						ptPlayList = new CTimeList();
						*ptPlayList = *ptIndex2;
						m_arrPlayList.Add(ptPlayList);
						m1++;
						break;
					case -3:
					case -2:
						ptPlayList = new CTimeList();
						*ptPlayList = *ptIndex2;
						ptPlayList->SetEndTime(ptIndex1->GetStartTime(), ptIndex1->GetStartMilliSec());
						m_arrPlayList.Add(ptPlayList);
						m1++;
						break;
					case -1:
					case 0:
					case 1:
					case 6:
						m1++;
						break;
					case 2:
						//				case 3:
						ptIndex2->SetStartTime(ptIndex1->GetEndTime(), ptIndex1->GetEndMilliSec());
						bBreak = TRUE;
						break;
					case 3:
						ptIndex1->SetEndTime(ptIndex2->GetStartTime(), ptIndex2->GetStartMilliSec());
						bBreak = TRUE;
						break;
					case 4:
					case 5:
						bBreak = TRUE;
						break;
					}

				}

				ptPlayList = new CTimeList();
				*ptPlayList = *ptIndex1;
				m_arrPlayList.Add(ptPlayList);
			}


			for (;m1<pArrIndex[nLoop-2]->GetSize();m1++)
			{
				ptPlayList = new CTimeList();
				ptIndex2 = pArrIndex[nLoop-2]->GetAt(m1);
				*ptPlayList = *ptIndex2;
				m_arrPlayList.Add(ptPlayList);
			}

			for (m1=0;m1<m_arrPlayList.GetSize();m1++)
			{
				ptIndex2 = m_arrPlayList.GetAt(m1);

				if (ptIndex2->GetAllInterval()<1)
				{
					delete ptIndex2;
					m_arrPlayList.RemoveAt(m1);
					m1--;
					continue;
				}
			}

			for (m1=0;m1<pArrIndex[nLoop-2]->GetSize();m1++)
			{
				ptIndex1 = pArrIndex[nLoop-2]->GetAt(m1);
				delete ptIndex1;
			}
			pArrIndex[nLoop-2]->RemoveAll();

			for (m1=0;m1<pArrIndex[nLoop-1]->GetSize();m1++)
			{
				ptIndex1 = pArrIndex[nLoop-1]->GetAt(m1);
				delete ptIndex1;
			}
			pArrIndex[nLoop-1]->RemoveAll();
			//////////////////////////////////////////////////////////////////////////
			//arrCompareTemp.RemoveAll();
			if (nLoop == 2)
			{
				break;
			}
			nLoop--;

			for (i=0;i<m_arrPlayList.GetSize();i++)
			{
				arrCompareTemp.Add(m_arrPlayList.GetAt(i));
			}
			pArrIndex[nLoop-1] = &arrCompareTemp;
			m_arrPlayList.RemoveAll();
		}
	}

}

void CWndListEvent::ArrangeRecList()
{
	m_SkinList.DeleteAllItems();

	int i;
	CTimeList *ptIndex;
	for (i=0;i<m_arrPlayList.GetSize();i++)
	{
		ptIndex = m_arrPlayList.GetAt(i);
		delete ptIndex;
	}
	m_arrPlayList.RemoveAll();

	MergetList();

	CString cszItem;	
	TCHAR tzStr[64] = {0};

	for (i=0;i<m_arrPlayList.GetSize();i++)
	{
		ptIndex = m_arrPlayList.GetAt(i);
		m_SkinList.InsertItem(i, _T(""));

		cszItem.Format(_T("%s"), m_pListMgr->GetRecTypeString(ptIndex->GetRecType()));

		m_SkinList.SetItemText(i, 1, cszItem);

		// Start Time
		m_UtilTime.GetDateTimeString(ptIndex->GetStartTime(), tzStr);
		m_SkinList.SetItemText(i, 2, tzStr);

		// End Time
		m_UtilTime.GetTimeString(ptIndex->GetEndTime(), tzStr);
		m_SkinList.SetItemText(i, 3, tzStr);
	}

	m_SkinList.SetRedraw(TRUE);

	ListView_SetExtendedListViewStyle(m_SkinList.m_hWnd, LVS_EX_FULLROWSELECT | LVS_EX_HEADERDRAGDROP | LVS_EX_CHECKBOXES);

	if (m_arrPlayList.GetSize()<=0)
		return;

	//m_SkinList.SetItemIndicate(0);

}

void CWndListEvent::LoadRecList()
{
	ArrangeRecList();
}

void CWndListEvent::ResetList()
{
	m_SkinList.DeleteAllItems();

	CTimeList *ptIndex;
	int i;
	for (i=0;i<m_arrPlayList.GetSize();i++)
	{
		ptIndex = m_arrPlayList.GetAt(i);
		delete ptIndex;
	}
	m_arrPlayList.RemoveAll();

	if (m_bChecked == TRUE)
		NotifyCheckStatus(FALSE);

	//m_SkinList.SetItemIndicate(-1);			//#417
}


void CWndListEvent::SetCheckAll()
{
	for (int i=0; i<m_SkinList.GetItemCount(); i++)
	{
		m_SkinList.SetCheck(i, TRUE);		
	}

	if (m_bChecked == FALSE && m_SkinList.GetItemCount()>0)
		NotifyCheckStatus(TRUE);
}

void CWndListEvent::SetUncheckAll()
{
	for (int i=0; i<m_SkinList.GetItemCount(); i++)
	{
		m_SkinList.SetCheck(i, FALSE);		
	}

	if (m_bChecked == TRUE)
		NotifyCheckStatus(FALSE);
}


BOOL CWndListEvent::OnEraseBkgnd(CDC* pDC)
{
	return CWnd::OnEraseBkgnd(pDC);
}

long CWndListEvent::OnCtlMessage(UINT wParam, LONG lParam)
{
	int nControlID		= LOWORD(wParam);			// Control ID
	int nMsg			= HIWORD(wParam);
	int nControlValue	= lParam;

	switch (nControlID)
	{
		case WM_LIST_MSG:
			{
				if (nControlValue == 2)		SetCheckAll();
				else						SetUncheckAll();

				break;
			}
		case WM_LIST_CHECK:
			{
				CSkinListCtrl *pListCtrl = (CSkinListCtrl *)GetDlgItem(nMsg);
				int i, nCnt;
				for (i=0,nCnt=0;i<pListCtrl->GetItemCount();i++)
				{
					if (pListCtrl->GetCheck(i))
						nCnt++;
				}
// 				if (pListCtrl->GetItemCount() == nCnt)
// 					pListCtrl->SetHeaderCheck(CHECKED);
// 				else
// 					pListCtrl->SetHeaderCheck(UNCHECKED);

				if (nCnt>0)
				{
					if (m_bChecked == FALSE)
						NotifyCheckStatus(TRUE);
				}
				else
				{
					if (m_bChecked == TRUE)
						NotifyCheckStatus(FALSE);
				}

			}
	}

	return 0;
}

long CWndListEvent::OnPlbMessage(UINT wParam, LONG lParam)
{
	CWnd* pParent = GetParent();
	int nItem = (int)lParam;
	if (nItem<0)
		return 0;
	//m_SkinList.SetItemIndicate(lParam);
	pParent->PostMessage(WM_PLB_MESSAGE, wParam, lParam);
	
	return 0;
}

CTimeList *CWndListEvent::GetBackupIndex(int nIndex)
{
	return GetRecIndex(nIndex);
}

void CWndListEvent::NotifyCheckStatus(BOOL bChecked)
{
	CWnd *pParent = GetParent();
	m_bChecked = bChecked;
	pParent->PostMessage(WM_PLB_MESSAGE, WM_EVENT_LIST_CHECK_STATUS, m_bChecked);
}

int CWndListEvent::SearchIndex(time_t tSearchTime, BOOL bFindNearBehind)
{
	int nIndex;
	BOOL bFind = FALSE;
	nIndex = binarySearchIndex(tSearchTime, 0, m_arrPlayList.GetSize()-1, &bFind);

	if (bFind)
		return nIndex;

	if (!bFindNearBehind)
		nIndex--;

	if ((nIndex<0)||(nIndex>=m_arrPlayList.GetSize()))
		return -1;
	return nIndex;
}

int CWndListEvent::binarySearchIndex(time_t tSearchTime, int nStart, int nEnd, BOOL *bFind)
{
	if ((nEnd-nStart)<8)
	{
		return linearSearchIndex(tSearchTime, nStart, nEnd, bFind);
	}

	int nMid = nStart + (nEnd-nStart)/2;
	int nRet;

	CTimeList *ptIndex = m_arrPlayList.GetAt(nMid);
	nRet = ptIndex->TimeInIndex(tSearchTime, 0);
	if (nRet == 0)
	{
		*bFind = TRUE;
		return nMid;
	}
	else if (nRet<0)
		return binarySearchIndex(tSearchTime, nStart, nMid-1, bFind);
	return binarySearchIndex(tSearchTime, nMid+1, nEnd, bFind);

}

int CWndListEvent::linearSearchIndex(time_t tSearchTime, int nStart, int nEnd, BOOL *bFind)
{
	int i;
	int nRet1, nRet2 = 0;
	CTimeList *ptIndex;
	*bFind = FALSE;
	for (i=nStart;i<=nEnd;i++)
	{
		ptIndex = m_arrPlayList.GetAt(i);
		nRet1 = ptIndex->TimeInIndex(tSearchTime, 0);
		if (nRet1 == 0)
		{
			*bFind = TRUE;
			return i;
		}
		else if (nRet1<0)
		{
			return i;
		}
	}
	return i;
}

void CWndListEvent::SetSelectRecType(DWORD dwRecType, BOOL bChecked)
{
	m_bRecType[dwRecType] = bChecked;
}

int CWndListEvent::GetCurrentRecIndexNumber()
{
	return 2;//m_SkinList.GetItemIndicate();
}

int CWndListEvent::GetRecIndexNumberAvailable(int nIndexNumber)
{
	if ((nIndexNumber<0) || (nIndexNumber>=m_arrPlayList.GetSize()))
		return -1;
	return nIndexNumber;


}

CTimeList *CWndListEvent::GetRecIndex(int nIndexNumber)
{
	return m_arrPlayList.GetAt(nIndexNumber);
}

void CWndListEvent::SetRecIndex(int nIndexNumber)
{
	if ((nIndexNumber<0)||(nIndexNumber>=m_arrPlayList.GetSize()))		//#417
		return;
	//m_SkinList.SetItemIndicate(nIndexNumber);
}

int CWndListEvent::GetRecIndexSize()
{
	return m_arrPlayList.GetSize();
}

int CWndListEvent::GetBackupIndexStart()
{
	int nIndex;
	for (nIndex=0;nIndex<m_SkinList.GetItemCount();nIndex++)
	{
		if (m_SkinList.GetCheck(nIndex))
			return nIndex;
	}
	return -1;
}

int CWndListEvent::GetBackupIndexNext(int nIndex, BOOL bChecked)
{
	nIndex++;
	if (nIndex>=m_SkinList.GetItemCount())
		return -1;
	if (nIndex<0)
		return -1;

	if (bChecked)
	{
		for (;nIndex<m_SkinList.GetItemCount();nIndex++)
		{
			if (m_SkinList.GetCheck(nIndex))
				return nIndex;
		}
	}
	else
	{
		return nIndex;
	}
	return -1;
}

int CWndListEvent::GetBackupIndexEnd()
{
	int nIndex = -1;
	int i;
	for (i=0;i<m_SkinList.GetItemCount();i++)
	{
		if (m_SkinList.GetCheck(i))
			nIndex = i;
	}

	return nIndex;
}

BOOL CWndListEvent::PreTranslateMessage(MSG* pMsg)
{
	return CWnd::PreTranslateMessage(pMsg);
}

void CWndListEvent::RefreshLang()
{
	LVCOLUMN lvCol;
	ZeroMemory(&lvCol, sizeof(lvCol));
	lvCol.mask = LVCF_TEXT;

	lvCol.pszText = (LPWSTR)(LPCTSTR)m_pListMgr->GetString(5);
	lvCol.cchTextMax = m_pListMgr->GetString(5).GetLength();
	m_SkinList.SetColumn(1, &lvCol);

	lvCol.pszText = (LPWSTR)(LPCTSTR)m_pListMgr->GetString(2);
	lvCol.cchTextMax = m_pListMgr->GetString(2).GetLength();
	m_SkinList.SetColumn(2, &lvCol);

	lvCol.pszText = (LPWSTR)(LPCTSTR)m_pListMgr->GetString(3);
	lvCol.cchTextMax = m_pListMgr->GetString(3).GetLength();
	m_SkinList.SetColumn(3, &lvCol);

	m_SkinList.DeleteAllItems();
	ArrangeRecList();
}